<template>
  <Back />
  <div class="page">
    <div class="flex justify-between tag">
      <div :class="{ active: type == 0 }" @click="getData(0)">{{ $t('prize.start') }}</div>
      <div :class="{ active: type == 1 }" @click="getData(1)">{{ $t('prize.end') }}</div>
    </div>

    <div style="padding-bottom: 150px">
      <van-empty v-if="list.finished && list.data.length < 1" :description="$t('common.noData')" />
      <van-list
        v-if="!list.finished || list.data.length > 0"
        v-model:loading="list.loading"
        :finished="list.finished"
        @load="getList"
        :immediate-check="false"
      >
        <div v-for="item in list.data" :key="item.id" class="record">
          <div class="flex" @click="go('/agentProduct?id=' + item.id)">
            <div>
              <img :src="item.img" />
            </div>
            <div class="flex flex-col justify-between">
              <div class="font-size-16px">{{ item.name }}</div>
              <div>{{ item.endTime }}</div>
              <div>{{ $t('prize.people') }} {{ item.currAmount }}/{{ item.totalAmount }}</div>
              <div>
                <van-button :disabled="type == 1" size="small" block type="primary" round>{{ $t('prize.join') }}</van-button>
              </div>
            </div>
          </div>
        </div>
      </van-list>
    </div>

    <div class="foot">
      <div class="flex justify-between m-b-10px">
        <div class="font-size-1.2rem color-#9c9c9c">{{ $t('agent.number') }}</div>
        <div class="font-size-1.6rem font-bold">{{ user?.agentNumber }}</div>
      </div>
      <div class="text-center m-b-4px font-size-1.4rem">{{ $t('agent.offical') }}TEAWOO_UZ_SUPPTOR</div>
      <div class="flex">
        <van-button block type="primary" round @click="cs"> {{ $t('agent.cs') }} </van-button>
        <div class="w-16px"></div>
        <van-button block type="primary" round @click="go('/agentOrders')"> {{ $t('agent.orders') }} </van-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const router = useRouter()

// 0进行中 1已结束
const type = ref(0)

const { getList, list, reset } = useList(apis.api.userAgentProductPage, { type: type.value })

const user = ref<ApiUser>()

function go(path: string) {
  router.push(path)
}

const getData = (t: number) => {
  type.value = t
  reset()
  list.query.type = t
  getList()
}

function cs() {
  location.href = 'https://t.me/Teawoo_uz_support'
}

onMounted(async () => {
  apis.api.userAgentInfo().then(d => {
    user.value = d
  })
  list.loading = true
  getList()
})
</script>

<style lang="scss" scoped>
.page {
  box-sizing: border-box;
  min-height: 100vh;
  background-color: #fafafa;
}
.record {
  margin: 16px 16px 0;
  background-color: #fff;
  border-radius: 4px;
  padding: 8px 8px;
  font-size: 14px;
  img {
    width: 100px;
    height: 100px;
    margin-right: 10px;
  }
}
.red {
  color: #fb553c;
}
.green {
  color: #3aa1a2;
}

.tag {
  padding: 16px;
  font-size: 14px;
  > div {
    text-align: center;
    border-radius: 5px;
    background-color: #dcdcdc;
    line-height: 40px;
    width: 46%;
  }
  .active {
    background-color: #3aa1a2;
    color: #fff;
  }
}
.foot {
  border-top: 1px solid #dcdcdc;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 12px;
}
</style>
